<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/agul.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/agul.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/agul.png?v=5.1.4">






  <meta name="keywords" content="服务端笔记,php," />




  


  <link rel="alternate" href="/atom.xml" title="Agul'blog" type="application/atom+xml" />






<meta name="description" content="配置 PHP 支持Apache 只能处理静态文件请求，对于后缀名为 .php 这种动态文件，它无法执行，所以就当成是一 个静态文件直接返回。  在服务器上安装 PHP   解压 php 到纯英文路径目录中   在 Apache 中添加支持 PHP 的配置   在 Apache 添加 PHP 处理模块    1LoadModule php7_module 路径  在 &lt;IfModule mim">
<meta property="og:type" content="article">
<meta property="og:title" content="接触php">
<meta property="og:url" content="https://ultraman-agul.github.io/2020/05/17/%E6%8E%A5%E8%A7%A6php/index.html">
<meta property="og:site_name" content="Agul&#39;blog">
<meta property="og:description" content="配置 PHP 支持Apache 只能处理静态文件请求，对于后缀名为 .php 这种动态文件，它无法执行，所以就当成是一 个静态文件直接返回。  在服务器上安装 PHP   解压 php 到纯英文路径目录中   在 Apache 中添加支持 PHP 的配置   在 Apache 添加 PHP 处理模块    1LoadModule php7_module 路径  在 &lt;IfModule mim">
<meta property="og:image" content="https://ultraman-agul.github.io/images/php1.png">
<meta property="article:published_time" content="2020-05-17T01:16:44.000Z">
<meta property="article:modified_time" content="2020-05-17T10:31:57.639Z">
<meta property="article:author" content="agul">
<meta property="article:tag" content="服务端笔记">
<meta property="article:tag" content="php">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://ultraman-agul.github.io/images/php1.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://ultraman-agul.github.io/2020/05/17/接触php/"/>





  <title>接触php | Agul'blog</title>
  








<meta name="generator" content="Hexo 4.2.0"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Agul'blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">Record a good life</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://ultraman-agul.github.io/2020/05/17/%E6%8E%A5%E8%A7%A6php/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="agul">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/agul1.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Agul'blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">接触php</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-05-17T09:16:44+08:00">
                2020-05-17
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/php/" itemprop="url" rel="index">
                    <span itemprop="name">php</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="配置-PHP-支持"><a href="#配置-PHP-支持" class="headerlink" title="配置 PHP 支持"></a>配置 PHP 支持</h1><p>Apache 只能处理静态文件请求，对于后缀名为 .php 这种动态文件，它无法执行，所以就当成是一 个静态文件直接返回。</p>
<ul>
<li><p>在服务器上安装 PHP </p>
<ul>
<li>解压 php 到纯英文路径目录中</li>
</ul>
</li>
<li><p>在 Apache 中添加支持 PHP 的配置 </p>
<p> 在 Apache 添加 PHP 处理模块 </p>
</li>
</ul>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">LoadModule php7_module 路径</span><br></pre></td></tr></table></figure>

<pre><code>在 &lt;IfModule mime_module&gt; 节点中添加 .php 扩展名解析支持 </code></pre><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">AddType application/x‐httpd‐php .php</span><br></pre></td></tr></table></figure>

<p>​        默认文档配置节点 <IfModule dir_module> 中添加 index.php，默认文档指的是在访问一个目录而不是具体文件名时，默认执行的文件名</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&lt;IfModule dir_module&gt; </span><br><span class="line">    DirectoryIndex index.html index.php </span><br><span class="line">&lt;/IfModule&gt;</span><br></pre></td></tr></table></figure>

<ul>
<li>重启Apache</li>
</ul>
<h3 id="Apache与PHP"><a href="#Apache与PHP" class="headerlink" title="Apache与PHP"></a>Apache与PHP</h3><p>我们不能把他们混在一起，他们两者各自有各自负责的领域，各自的职责，但是我们在使用 PHP 做动态网站开发时，两者就会产生联系，具体如下：</p>
<p><img src="/images/php1.png" alt=""></p>
<blockquote>
<p>你可以理解为：Apache 是一家没有太多能力的公司，只能处理一些简单的业务（静态网站），但是心很大想 做更多的事（动态网站），所以就想到了外包，所有额外的业务都需要外包给其他程序，而 PHP 就是理解为 一个专门能够处理 php 业务的外包公司</p>
</blockquote>
<h1 id="PHP"><a href="#PHP" class="headerlink" title="PHP"></a>PHP</h1><p>类似于在 HTML 中使用 JavaScript，但是不同的是 JavaScript 运行在客户端，而 PHP 运行在服务端。 只有处于 PHP 标记内部的代码才是 PHP 代码，PHP 标记以外都原封不动。</p>
<ol>
<li><p>PHP 标记</p>
<ul>
<li>&lt;?php  进入PHP模式</li>
<li>?&gt; 退出PHP模式</li>
<li>类似于在 HTML 中使用 JavaScript，但是不同的是 JavaScript 运行在客户端，而 PHP 运行在服务端。 只有处于 PHP 标记内部的代码才是 PHP 代码，PHP 标记以外都原封不动。</li>
<li>省略结束标记：当PHP处于文件末尾时，省略结束标记，方式出现额外空行。</li>
</ul>
</li>
<li><p>输出内容格式</p>
<ul>
<li><p>echo </p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// echo 是 PHP 中的一个特殊的“指令”，</span></span><br><span class="line"><span class="comment">// 不一定需要像函数那样通过 `()` 去使用 </span></span><br><span class="line"><span class="comment">// 注意：echo 后面紧跟着一个空格 </span></span><br><span class="line"><span class="keyword">echo</span> <span class="string">'hello php'</span>; </span><br><span class="line"><span class="keyword">echo</span> <span class="string">'hello'</span>, <span class="string">'world'</span>;  <span class="comment">//可以输出多个参数</span></span><br><span class="line"><span class="comment">// =&gt; `helloworld`</span></span><br></pre></td></tr></table></figure>



</li>
</ul>
</li>
</ol>
<ul>
<li><p>print</p>
<p> print 与 echo 唯一区别就是只能有一个参数 print ‘hello’; </p>
</li>
<li><p>var_dump</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span> </span><br><span class="line"><span class="comment">// var_dump 是一个函数，必须跟上 () 调用 </span></span><br><span class="line"><span class="comment">// 可以将数据以及数据的类型打印为特定格式 var_dump('hello php'); </span></span><br><span class="line"><span class="comment">// =&gt; 'string(9) "hello php"'</span></span><br></pre></td></tr></table></figure>

<p>还有一些输出函数，先不说。。</p>
</li>
</ul>
<ol start="3">
<li><p>与HTML混编</p>
<ul>
<li><p>普通嵌入</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;p&gt;<span class="meta">&lt;?php</span> <span class="keyword">echo</span> <span class="string">'hello'</span>; <span class="meta">?&gt;</span>&lt;/p&gt;</span><br></pre></td></tr></table></figure>
</li>
<li><p>语句混编</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span> <span class="keyword">if</span> ($age &gt; <span class="number">18</span>): <span class="meta">?&gt;</span>   </span><br><span class="line">	&lt;p&gt;成年人&lt;/p&gt; </span><br><span class="line"><span class="meta">&lt;?php</span> <span class="keyword">else</span>: <span class="meta">?&gt;</span> </span><br><span class="line"> 	 &lt;p&gt;小朋友&lt;/p&gt; </span><br><span class="line"><span class="meta">&lt;?php</span> <span class="keyword">endif</span> <span class="meta">?&gt;</span></span><br></pre></td></tr></table></figure>
</li>
</ul>
</li>
<li><p>注释</p>
<ul>
<li>单行====&gt;  // 或 #</li>
<li>多行====&gt; /*  内容   */</li>
</ul>
</li>
<li><p>语法</p>
<ul>
<li>和其他编程语言大同小异</li>
</ul>
</li>
<li><p>变量</p>
<ul>
<li>PHP 中申明一个变量是用一个美元符号后面跟变量名来表示。</li>
<li>变量名同样是区分大小写的。</li>
<li>PHP 中变量无需声明类型，变量的类型根据值的类型来推断。</li>
</ul>
</li>
</ol>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span> </span><br><span class="line">$foo; <span class="comment">// 申明一个变量，变量名为 `foo`，未对其进行赋值 </span></span><br><span class="line">$bar = <span class="string">'baz'</span>; <span class="comment">// 申明一个变量，将一个值为 `baz` 的字符串赋值给它 </span></span><br><span class="line"><span class="keyword">echo</span> $foo; <span class="comment">// 输出一个变量名为 `foo` 的变量 </span></span><br><span class="line">fn($bar); <span class="comment">// 将一个变量名为 `foo` 的变量作为 `fn` 的实参传递</span></span><br></pre></td></tr></table></figure>

<ol start="7">
<li><p>超全局变量</p>
<p>PHP 中的许多预定义变量都是“超全局的”，这意味着它们在一个脚本的全部作用域中都可用。在函数或方法中无需执行 global $variable; 就可以访问它们。</p>
<p>这些超全局变量是：</p>
<ul>
<li>$GLOBALS — 引用全局作用域中可用的全部变量</li>
<li>$_SERVER — 获取服务端相关信息 </li>
<li>$_REQUEST — 获取提交参数 </li>
<li>$_POST — 获取 POST 提交参数 </li>
<li>$_GET — 获取 GET 提交参数 </li>
<li>$_FILES — 获取上传文件 </li>
<li>$_ENV — 操作环境变量 </li>
<li>$_COOKIE — 操作 Cookie</li>
<li>$_SESSION — 操作 Session</li>
</ul>
</li>
<li><p>常量</p>
<ul>
<li><p>定义</p>
</li>
<li><pre><code class="php"><span class="meta">&lt;?php</span> 
<span class="comment">// 定义常量使用的是内置的 `define` 函数 </span>
<span class="comment">// 第一个参数是常量的名称，建议采用全大写字母命名，多个单词下划线分隔 </span>
<span class="comment">// 第二个参数是常量中存放的数据，可以是任意类型 </span>
<span class="comment">// 第三个参数是常量名称是否区不分大小写，默认 false 区分大小写 </span>
define(<span class="string">'SYSTEM_NAME'</span>, <span class="string">'大百度'</span>); 
define(<span class="string">'SYSTEM_ENABLE'</span>, <span class="keyword">true</span>);
&lt;!--￼<span class="number">8</span>--&gt;


</code></pre>
</li>
</ul>
</li>
</ol>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/%E6%9C%8D%E5%8A%A1%E7%AB%AF%E7%AC%94%E8%AE%B0/" rel="tag"># 服务端笔记</a>
          
            <a href="/tags/php/" rel="tag"># php</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2020/05/17/%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%BC%80%E5%8F%91%E5%9F%BA%E7%A1%80/" rel="next" title="服务器开发基础">
                <i class="fa fa-chevron-left"></i> 服务器开发基础
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2020/05/18/Node%E5%9F%BA%E7%A1%80/" rel="prev" title="Node.js 基础">
                Node.js 基础 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/agul1.png"
                alt="agul" />
            
              <p class="site-author-name" itemprop="name">agul</p>
              <p class="site-description motion-element" itemprop="description">天行健，君子以自强不息</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/%7C%7C%20archive">
              
                  <span class="site-state-item-count">13</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">9</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">13</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#配置-PHP-支持"><span class="nav-number">1.</span> <span class="nav-text">配置 PHP 支持</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Apache与PHP"><span class="nav-number">1.0.1.</span> <span class="nav-text">Apache与PHP</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#PHP"><span class="nav-number">2.</span> <span class="nav-text">PHP</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">agul</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
